package com.freejy.ecommunity.web.controller;


import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.freejy.ecommunity.model.TopicReply;
import com.freejy.ecommunity.service.TopicReplyService;

@RestController
public class TopicReplyController extends BaseController{

    @Autowired
    private TopicReplyService topicReplyService;

    
    /**
     * 根据板块id分页获取帖子信息
     * @return
     */
    @RequestMapping("/getTopicReplysByTopicId")
    public ResponseEntity<?> getTopicsByPlateId(@Valid @RequestBody String  info){
    	JSONObject json=JSONObject.parseObject(info);
        return success(topicReplyService.getTopicReplysByTopicId(json.getInteger("topicId").intValue(),json.getInteger("size") ,json.getInteger("limit") ));
    }
    
    /**
     * 新增回复
     * @return
     */
    @RequestMapping("/insertTopicReply")
    public ResponseEntity<?> insertTopicReply(@Valid @RequestBody String  info){
    	JSONObject json=JSONObject.parseObject(info);
    	TopicReply topicReply = (TopicReply) JSONObject.toJavaObject(json, TopicReply.class);
        return success(Integer.valueOf(topicReplyService.insert(topicReply)));
    }
    
    
}
